package com.hand.wfive.ad;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.hand.wfive.base.BaseFragment;
import com.hand.wfive.util.FuncSwitchUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public abstract class AdFragment extends BaseFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerEventBus();
    }

    /**
     * 必须vip
     */
    protected void showVip() {
        /*if (BuildConfig.DEBUG){
            adCloseCallBack();
            return;
        }*/
        FuncSwitchUtils.refreshUserStatus();
        AdActivity.curVideoClass = getClass().getName();
        AdManager.getInstance().doVipIntent(mActivity);
    }

    /**
     * 后台开关：开：必须vip  关：功能免费使用一次；
     */
    protected void showVip(String funcType) {
        if (FuncSwitchUtils.canUse(funcType)) {
            fragmentAdClose();
            return;
        }
        AdActivity.curVideoClass = getClass().getName();
        AdManager.getInstance().doVipIntent(mActivity);
    }

    /**
     * 列表里免费查看两条
     */
    protected void showVip(int position) {
        if (FuncSwitchUtils.canUseByPosition(position ,2)) {
            fragmentAdClose();
            return;
        }
        AdActivity.curVideoClass = getClass().getName();
        AdManager.getInstance().doVipIntent(mActivity);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void adClose(ADCloseEvent event) {
        if (getClass().getName().equals(AdActivity.curVideoClass)) {
            AdActivity.curVideoClass = null;
            fragmentAdClose();
        }
    }

    protected void fragmentAdClose() {
    }

}
